package com.woniuxy.personal.core.mapper;

import com.woniuxy.personal.core.model.PlOrder;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.woniuxy.personal.core.model.PlOrderitem;
import com.woniuxy.personal.core.vo.OrderVo;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author gmx
 * @since 2021-06-29
 */
public interface PlOrderMapper extends BaseMapper<PlOrder> {

    @Select("select * from pl_order where ordernumber = #{ordernumber}")
    PlOrder selectByOrdernumber(String ordernumber);

    List<OrderVo> selectOrderList(int user_id);

    @Select("select * from pl_order where status=0 and user_id=#{value}" )
    List<OrderVo> selectNonpaymentOrderList(int user_id);
    @Select("select * from pl_order where status=1 and user_id=#{value}" )
    List<OrderVo> selectPaidOrderList(int user_id);
    @Select("select * from pl_order where status=2 and user_id=#{value}" )
    List<OrderVo> selectNonServiceOrderList(int user_id);
    @Select("select * from pl_order where status=3 and user_id=#{value}" )
    List<OrderVo> selectNonAppraiseOrderList(int user_id);
    @Select("select * from pl_order where status=4 and user_id=#{value}" )
    List<OrderVo> selectNonAfterServiceOrderList(int user_id);
    @Select("select * from pl_order where status=5 and user_id=#{value}" )
    List<OrderVo> selectFinishedOrderList(int user_id);
    @Update("update pl_order set status=1 where id=#{id} and user_id=#{user_id}")
    int payOrder(int id,int user_id);
    @Update("update pl_order set status=3 where id=#{id} and user_id=#{user_id}")
    int confirm(int id,int user_id);
    @Delete("delete from pl_order where id=#{id} and user_id=#{user_id}")
    int cancelOrder(int user_id,int id);

    @Update("update pl_order set total_price=#{totalPrice} where ordernumber=#{ordernumber}")
    void addTotalPrice(BigDecimal totalPrice, String ordernumber);

    @Select("select ordernumber from pl_order where id = #{id}")
    String selectOrderNumber(int id);

    @Select("select createtime from pl_order where id = #{orderId}")
    Date seletTimeByOrderId(Integer orderId);
}
